package cn.lu.joke.mvp.presenter.user;

import java.io.File;

import cn.lu.joke.App;
import cn.lu.joke.entry.ResultData;
import cn.lu.joke.entry.User;
import cn.lu.joke.mvp.model.CallbackImpl;
import cn.lu.joke.mvp.model.DataModelManager;
import cn.lu.joke.mvp.model.UserModel;
import cn.lu.joke.mvp.presenter.BasePresenter;
import cn.lu.joke.mvp.view.IUserView;

public class UserInfoPresenter extends BasePresenter<IUserView.IUpdateUserInfo> implements IHeadImgPresenter {

    public UserInfoPresenter(IUserView.IUpdateUserInfo view) {
        super(view);
    }

    @Override
    public void updateUserInfo(File headImg, String nickName, String sex, String birth, String city, String sign) {
        User user = App.getLoginUser();
        if (user.name.equals(nickName)) {
            nickName = null;
        }
        if (user.sex.equals(sex)) {
            sex = null;
        }
        if (user.birth != null && user.birth.equals(birth)) {
            birth = null;
        }
        if (user.city != null && user.city.equals(city)) {
            city = null;
        }
        if (user.sign != null && user.sign.equals(sign)) {
            sign = null;
        }
        if (user.name.equals(nickName)) {
            nickName = null;
        }
        DataModelManager.create(UserModel.class)
                .updateUserInfo(headImg, nickName, sex, birth, city, sign, new CallbackImpl<ResultData<User>, IUserView.IUpdateUserInfo>(getView()) {
                    @Override
                    public void onSuccess(ResultData<User> data) {
                        getView().onUpdateUserInfo(data);
                    }
                });
    }
}
